package be.sc.classicnetwork.dao;

import java.util.List;

import be.sc.classicnetwork.model.AbstractEntity;

/**
 * Super interface for DAOs having common CRUD functionalities.
 */
public interface GenericDao<T extends AbstractEntity> {
    /**
     * Finds the specified entity. The default fetching strategy defined by the
     * attribute annotions will be used.
     * 
     * @param id
     *                the entity id
     * @return the entity or null if not found
     */
    T findById(String id);

    /**
     * Finds the specified entity. All the relationships (OneToMany &&
     * ManyToMany) will be fetched.
     * 
     * @param id
     *                the entity id
     * @return the entity or null if not found
     */
    T findByIdWithFullDependencies(String id);

    /**
     * Finds the specified entity and fetch the specified dependencies.
     * 
     * @param id
     *                the entity id
     * @param dependencies
     *                the dependencies
     * @return the entity or null if not found
     */
    T findByIdWithDependencies(String id, String... dependencies);

    /**
     * Gets all the entities.
     * 
     * @param first
     *                the first result (from 0)
     * @param max
     *                the max number of record to retrieve (<= 0 for no limit)
     * @return a List of 0 or more persitent entities
     */
    List<T> findAll(int first, int max);

    /**
     * Generates a unique entity id and saves (insert or update) the specified
     * entity.
     * 
     * @param entity
     *                the entity
     * @return a reference to the saved entity
     */
    T saveOrUpdate(T entity);

    /**
     * saveOrUpdateAny.
     */
    Object saveOrUpdateAny(Object o);

    /**
     * Deletes the specified entity.
     * 
     * @param entity
     *                the entity
     */
    void delete(T entity);

    /**
     * Deletes all the entities.
     */
    void deleteAll();

    /**
     * Counts all the entities.
     * 
     * @return the numbers of entities
     */
    int countAll();

    /**
     * Finds all the entities having the specified ids.
     * 
     * @param ids
     */
    List<T> findByIdIn(String... ids);

}
